package com.ktmall.ktmalluijava.controller;

import com.ktmall.ktmalluijava.pojo.Address;
import com.ktmall.ktmalluijava.service.AddressService;
import com.ktmall.ktmalluijava.utils.Page;
import com.ktmall.ktmalluijava.utils.ResMsg;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/5/13 上午11:06
 */
@RestController
@RequestMapping("/address")
public class AddressController {
    @Resource
    private AddressService service;

    @GetMapping ("/list")
    public String list(String username, String telName, String telNumber,
                       Integer pageNo , Integer pageSize){
        pageNo = pageNo == null ? 1 : pageNo;
        pageSize = pageSize == null ? 5 : pageSize;
        Page<Address> page = service.select(username, telName,telNumber, pageNo, pageSize);
        return ResMsg.success("收货地址列表加载成功",page);
    }

    @PostMapping("/del")
    public String del(@RequestBody Integer...id){
        int row = service.delete(id);
        if (row > 0) {
            return ResMsg.success("删除成功");
        } else {
            return ResMsg.error("删除失败");
        }
    }
}
